package com.lyr.controller;


import com.lyr.pojo.Employee;
import com.lyr.pojo.User;
import com.lyr.service.EmpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Api(tags ="雇员")
@RestController
@RequestMapping("/sys")
public class EmpController {
    @Autowired
    private EmpService empService;

    @ApiOperation(value = "查询员工")
    @PostMapping("/queryEmp")
    public Employee showEmployee(@RequestBody User user){
        if(!user.getUsername().equals("")){
            Employee emp = empService.getEmpByName(user.getUsername());
//            model.addAttribute("emp",emp);
            return emp;
        }else {
            //输入为空时显示所有用户
            return null;
        }

    }

//    @ApiOperation(value = "查询所有用户")
//    @PostMapping("/showAll")
//    public String showAll(Model model){
//        List<Employee> allEmp = empService.getAllEmp();
//        model.addAttribute("emp",allEmp);
//        return "show";
//    }
//
//
//    @PostMapping("/toAddEmp")
//    public String toAddEmp(){
//        return "addEmp";
//    }
//
//    //新增雇员信息
//    @ApiOperation(value = "新增雇员信息")
//    @PostMapping("/addEmp")
//    public String addEmp(Employee employee){
//        empService.addEmp(employee);
//        return "show";
//    }
//
//    //跳转到修改用户信息页面
//    @ApiOperation(value = "跳转到修改用户信息页面")
//    @RequestMapping("/toUpdate/{name}")
//    public String toUpdate(@PathVariable("name")String name,Model model){
//        Employee emp = empService.getEmpByName(name);
//        model.addAttribute("emp",emp);
//        return "updateEmp";
//    }
//
//    //修改员工信息
//    @ApiOperation(value = "修改员工信息")
//    @PutMapping("/updateEmp")
//    public String updateEmp(Employee employee){
//        empService.updateEmp(employee);
//        return "show";
//    }
//
//    //删除用户信息
//    @ApiOperation(value = "删除用户信息")
//    @DeleteMapping("/deleteEmp/{name}")
//    public String deleteEmp(@PathVariable("name")String name){
//        empService.deleteEmp(name);
//        return "show";
//    }


}
